package com.priserve.retirement.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Expression;

import com.priserve.retirement.core.exception.RetirementCoreDataException;
import com.priserve.retirement.entities.Advisor;
import com.priserve.retirement.entities.Clientinformation;

public class AdvisorDAO extends RetirementHibernateUtil{

	public AdvisorDAO() {

/*		Session session=getSession();
		session.saveOrUpdate(create());
		session.close();*/
	}
	
	
	public void saveAdvisor(){
		
		Advisor advisor=create();
		saveOrUpdate(advisor);
		System.err.println(" Saved the Advisor Successfully***********************");
	}
		private Advisor create(){
		
		Advisor advisor=new Advisor();
		advisor.setFirstName("First");
		advisor.setLastName("Advisor");
		advisor.setLoginId(Long.valueOf(2));
		return advisor;
	}
		
		
		public List<Clientinformation> getClientsByAdvisorId(final Long advisorId)throws RetirementCoreDataException{
			
			List<Clientinformation> clientList=null;
			try{
			Criteria criteria=createCriteria(Clientinformation.class);
		    clientList=criteria.add(Expression.eq("advisor.advisorId", advisorId)).list();
			}
			catch(Exception e){
				System.err.println("Exception at getClientsByAdvisorId::"+e.getMessage());
				new RetirementCoreDataException(e.getMessage());
			}
			return clientList;
		}

}
